package com.nsu.tly.web;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nsu.tly.dao.OrdersMapper;
import com.nsu.tly.entity.Orders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @Description:
 * @Author: Elder Tang
 * @Date: 2021/7/21 22:01
 */
@Controller
public class OrderController {

    @Autowired
    OrdersMapper ordersMapper;

    //显示所有的预约信息
    @GetMapping("/orders")
    public String getOrders(@RequestParam(value = "page", defaultValue = "1") Integer page, Model model) {
        //获取指定页数据，大小为8
        PageHelper.startPage(page, 8);
        //紧跟的第一个select方法被分页
        List<Orders> orders = ordersMapper.listOrders();
        //使用PageInfo包装数据
        PageInfo pageInfo = new PageInfo(orders, 5);
        model.addAttribute("pageInfo", pageInfo);
        return "page";
    }

}

